package com.hpin.mlxteacher.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hpin.mlxteacher.R;
import com.hpin.mlxteacher.bean.Family;

import java.util.List;

/**
 * Created by Aaron on 15/11/10.
 */
public class FamilyAdapter extends BaseAdapter {

    private Context ctx;
    private List<Family> families;

    public FamilyAdapter(Context ctx, List<Family> families) {
        this.ctx = ctx;
        this.families = families;
    }

    public void setFamilies(List<Family> families) {
        this.families = families;
    }

    @Override
    public int getCount() {
        return families.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;

        if (convertView == null) {

            convertView = View.inflate(ctx, R.layout.item_family, null);
            viewHolder = new ViewHolder();

            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_workspace = (TextView) convertView.findViewById(R.id.tv_workspace);
            viewHolder.tv_contact = (TextView) convertView.findViewById(R.id.tv_contact);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv_name.setText(families.get(i).name);
        viewHolder.tv_workspace.setText(families.get(i).workUnit);
        viewHolder.tv_contact.setText(families.get(i).phoneNum);


        return convertView;
    }

    private class ViewHolder {

        private TextView tv_name;
        private TextView tv_workspace;
        private TextView tv_contact;

    }

}
